// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0

import { ListView  } from "std-widgets.slint";

TestCase := Window {
    width: 400px;
    height: 540px;

    in-out property <string> value;
    out property listview-viewport-height <=> listview.viewport-height;
    out property listview-viewport-width <=> listview.viewport-width;
    out property listview-preferred-height <=> listview.preferred-height;

    out property <bool> test: true;



    listview := ListView {
        for data in [
            { text: "Blue", color: #0000ff, bg: #eeeeee},
            { text: "Red", color: #ff0000, bg: #eeeeee},
            { text: "Green", color: #00ff00, bg: #eeeeee},
            { text: "Yellow", color: #ffff00, bg: #222222 },
            { text: "Black", color: #000000, bg: #eeeeee },
            { text: "White", color: #ffffff, bg: #222222 },
            { text: "Magenta", color: #ff00ff, bg: #eeeeee },
            { text: "Cyan", color: #00ffff, bg: #222222 },
        ] : delegate := Rectangle {
            background: @linear-gradient(90deg, data.bg,data.bg.brighter(0.5));
            HorizontalLayout {
                text_Name := Text {
                    height: 100px;
                    text: data.text;
                    color: data.color;
                    font_size: 20px ;
                    min-width: 1500px;
                }
            }
            TouchArea { clicked => { value = data.text; } }
        }
    }
}

/*
```cpp
auto handle = TestCase::create();
const TestCase &instance = *handle;
slint_testing::send_mouse_click(&instance, 5., 205.);
assert_eq(instance.get_value(), "Green");
assert(instance.get_test());
assert_eq(instance.get_listview_viewport_height(), 8. * 100.);
assert_eq(instance.get_listview_viewport_width(), 1500.);

// scroll all the way down with the mouse wheel and click on the last item
for (int i = 0; i < 10; ++i) {
    instance.window().dispatch_pointer_scroll_event(slint::LogicalPosition({25.0, 105.0}), 0, -50);
}
slint_testing::send_mouse_click(&instance, 5., 441.);
assert_eq(instance.get_value(), "Cyan");
```

```rust
let instance = TestCase::new().unwrap();
slint_testing::send_mouse_click(&instance, 5., 205.);
assert_eq!(instance.get_value(), "Green");
assert!(instance.get_test());
assert_eq!(instance.get_listview_viewport_height(), 8. * 100.);
assert_eq!(instance.get_listview_viewport_width(), 1500.);

// scroll all the way down with the mouse wheel and click on the last item
use slint::{LogicalPosition, platform::WindowEvent };
for _ in 0..10 {
    instance.window().dispatch_event(WindowEvent::PointerScrolled { position: LogicalPosition::new(25.0, 105.0), delta_x: 0.0, delta_y: -50.0 });
}
slint_testing::send_mouse_click(&instance, 5., 441.);
assert_eq!(instance.get_value(), "Cyan");

```

```js
var instance = new slint.TestCase();
slintlib.private_api.send_mouse_click(instance, 5., 205.);
assert.equal(instance.value, "Green");
assert(instance.test);
assert.equal(instance.listview_viewport_height, 8. * 100.);
assert.equal(instance.listview_viewport_width, 1500.);
```

*/
